<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>渠道放开设置表 管理</title>
    <style type="text/css">
        .searchArea .fieldBox .label {
            width: 70px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">政策名称</div>
                    <div class="field">
                        <input name="policyNm" id="policyNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">事业部</div>
                    <div class="field">
                        <input name="buOrgCd" id="buOrgCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">项目类型</div>
                    <div class="field">
                        <input name="prjTypCd" id="prjTypCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">业务类型</div>
                    <div class="field">
                        <input name="bizTypCd" id="bizTypCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">保险类型</div>
                    <div class="field">
                        <input name="plcTypCd" id="plcTypCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">保险种类</div>
                    <div class="field">
                        <input name="insTypCd" id="insTypCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">状态</div>
                    <div class="field">
                        <input name="isValid" id="isValid" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <span id="addBtn" class="sq-button sq-button-round">新增</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<div id="expDt_div" style="display:none">
    <form id="expDt_formSet">
        <div class="fieldset1 tabel_col tabel_col_s noBorder clearFix">
            <div class="fieldBox col_50">
                <div class="label">延期至<span class="requiredSymbol">*</span></div>
                <div class="field">
                    <input name="expEndDt" id="expEndDt" type="text" class="ui-datepicker" value=""
                           validate="{required:true}">
                </div>
            </div>
        </div>
        <div class="btnsBox">
            <span id="confirmBtn" class="sq-button sq-button-round l-dialog-btn-ok">确定</span>
            <span id="cancelBtn" class="sq-button sq-button-round co_normal l-dialog-btn-cancel">取消</span>
        </div>
    </form>
</div>

<script type="text/javascript">
    var grid = null, callback = null, dataId = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/insurance/insChnOpenSetting/initList.do',
            method: 'get',
            columns: [
                {
                    display: '政策名称', name: 'policyNm', width: 100, align: 'left', enabledSort: false,
                    render: function (rowdata, index, value) {
                        var h = '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.policyNm + '">' + rowdata.policyNm + '</span>';
                        return h;
                    }
                },
                {
                    display: '有效期', name: 'expBgDt', width: 130, align: 'center', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        return renderDate(rowdata.expBgDt) + '-' + renderDate(rowdata.expEndDt);
                    }
                },
                {display: '状态', name: 'status', width: 60, align: 'center', enabledSort: false},
                {
                    display: '适用组织架构', name: 'buOrgCdNm', minWidth: 100, align: 'left', enabledSort: false,isEllipsis: false,
                    render: function (rowdata, index, value) {
                        var h = '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.buOrgCdNm + '">' + rowdata.buOrgCdNm + '</span>';
                        return h;
                    }
                },
                {
                    display: '适用项目类型',
                    name: 'prjTypCdNm',
                    minWidth: 100,
                    align: 'left',
                    enabledSort: false,
                    isEllipsis: false,
                    render: function (rowdata, index, value) {
                        var h = '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.prjTypCdNm + '">' + rowdata.prjTypCdNm + '</span>';
                        return h;
                    }
                },
                {
                    display: '适用业务类型', name: 'bizTypCdNm', minWidth: 100, align: 'left', enabledSort: false,isEllipsis: false,
                    render: function (rowdata, index, value) {
                        var h = '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.bizTypCdNm + '">' + rowdata.bizTypCdNm + '</span>';
                        return h;
                    }
                },
                /*{display: '适用区域', name: 'rgnCdNm', minWidth: 100, align: 'left', enabledSort: false,
                 render:function(rowdata,index,value){
                 var h='<span class="gridTip" style="cursor: pointer;" title="'+ rowdata.rgnCdNm +'">'+rowdata.rgnCdNm+'</span>';
                 return h;
                 }
                 },*/
                {
                    display: '适用保单类型', name: 'plcTypCdNm', minWidth: 100, align: 'left', enabledSort: false,isEllipsis: false,
                    render: function (rowdata, index, value) {
                        var h = '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.plcTypCdNm + '">' + rowdata.plcTypCdNm + '</span>';
                        return h;
                    }
                },
                {
                    display: '适用险种', name: 'insTypCdNm', minWidth: 100, align: 'left', enabledSort: false,isEllipsis: false,
                    render: function (rowdata, index, value) {
                        var h = '<span class="gridTip" style="cursor: pointer;" title="' + rowdata.insTypCdNm + '">' + rowdata.insTypCdNm + '</span>';
                        return h;
                    }
                },
                {
                    display: '操作', name: '', width: 175, align: 'left', enabledSort: false,
                    render: function (rowdata, rowindex, value) {
                        var h = '<a class="sq-button-hasicon" href="javascript:;" onclick="modifySetting(' + rowdata.id + ');"><i class="sqBtnIco_4"></i>修改</a>';
                        if (rowdata.isValid) {
                            h += '<a class="sq-button-hasicon" href="javascript:;" onclick="enable(' + rowdata.id + ',0);"><i class="sqBtnIco_13"></i>禁用</a>';
                        } else {
                            h += '<a class="sq-button-hasicon" href="javascript:;" onclick="enable(' + rowdata.id + ',1);"><i class="sqBtnIco_12"></i>启用</a>';
                        }
                        h += '<a class="sq-button-hasicon" href="javascript:;" onclick="modifyExp(' + rowdata.id + ');"><i class="sqBtnIco_4"></i>延期</a>';
                        return h;
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            fixedCellHeight: false,
        });
        grid.setHeight(100);

        $("#prjTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#bizTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#insTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#plcTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#buOrgCd").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });
        $("#isValid").ligerComboBox({
            valueField: 'key',
            textField: 'value'
        });

        $("#searchBar").ligerForm();
        liger.get("prjTypCd").setData(${prjTypCdList});
        liger.get("bizTypCd").setData(${bizTypCdList});
        liger.get("insTypCd").setData(${insTypCdList});
        liger.get("plcTypCd").setData(${plcTypCdList});
        liger.get("buOrgCd").setData(${buOrgCdList});
        liger.get("isValid").setData(${enableCdList});

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        callback = function () {
            grid.reload();
        };

        /* 新增 */
        $("#addBtn").click(function (event) {
            $.ligerDialog.open({
                width: 650,
                height: 420,
                title: '新增渠道放开设置表',
                url: '<%=path%>/insurance/insChnOpenSetting/toAddPage.do'
            });
        });

        $("#confirmBtn").click(function (event) {
            var ligerForm = liger.get("expDt_formSet");
            if (!ligerForm.valid()) {
                $.ligerDialog.SQalert({content: "请选延期截止时间！", SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = ligerForm.getData();
            $.ligerDialog.hide();
            data['id'] = dataId;

            var wait_dialog;
            $.ajax({
                url: '<%=path%>/insurance/insChnOpenSetting/modify.do',
                type: 'post',
                dataType: 'json',
                data: data,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload();
                        $.ligerDialog.hide();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });

        $("#cancelBtn").click(function (event) {
            $.ligerDialog.hide();
        });
    });

    //修改
    function modifySetting(_id) {
        $.ligerDialog.open({
            width: 650,
            height: 420,
            title: '修改渠道放开设置表',
            url: '<%=path%>/insurance/insChnOpenSetting/toModifyPage.do?id=' + _id
        });
    }

    function enable(_id, _status) {
        var wait_dialog;
        $.ajax({
            url: '<%=path%>/insurance/insChnOpenSetting/modify.do',
            type: 'post',
            dataType: 'json',
            data: {'id': _id, 'isValid': _status},
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                    grid.reload();
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
    //延期
    function modifyExp(_id) {
        dataId = _id;
        $.ligerDialog.SQopen({
            width: 400,
            title: '延期',
            target: $("#expDt_div")
        });
        $("#expDt_formSet").ligerForm({
            validate: true
        });
    }

    //格式化时间
    function renderDate(value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, "yyyyMMdd");
        }
        return dateStr;
    }

</script>

</body>
</html>
